package com.chis.jxc;

import com.chis.jmdatatimer.comm.TxMgmtModule;
import com.chis.jxc.bean.BactStmBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * @Description 查询mysql和hbase的库存表的数量是否一致，输出不一致的库存编码
 * @Company zwx
 * @author wlj
 * @version 2019年09月05日
 */
public class BalanceJxcStmcnt {
    public static void main(String[] args) throws Exception {
        String opt = args[0];
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"spring.xml"});
        context.start();
        TxMgmtModule txMgmtModule = (TxMgmtModule) context.getBean("TxMgmtModule");
        List<BactStmBean> mysqllist = txMgmtModule.findKcByZone();
        List<BactStmBean> hbaselist = txMgmtModule.findHbaseKc1();

        Map<String,Integer> mysql = new HashMap<>();
        for(BactStmBean b : mysqllist){
            mysql.put(b.getGuid(),b.getCntcount());
        }
        for(BactStmBean b : hbaselist){
            if(!mysql.containsKey(b.getGuid()) || !mysql.get(b.getGuid()).equals(b.getCntcount())){
                System.out.println(b.getGuid()+"  "+b.getCntcount()+" "+mysql.get(b.getGuid()));
                if(opt.equals("1")){
                    txMgmtModule.updateHbaseStm(b.getGuid(),mysql.containsKey(b.getGuid()) ? mysql.get(b.getGuid()) : 0);
                }
            }
        }


    }
}
